class WithdrawsController < ApplicationController
  before_filter :check_admin_right

  def new
    @agent = User.find(params[:id])
    @withdraw = Withdraw.new()
  end

  def create
    Withdraw.transaction do
      withdraw = Withdraw.new(params[:withdraw])
      agent = User.find(params[:withdraw][:user_id])
      withdraw.amount = agent.account
      withdraw.updater = current_user
      withdraw.save!
      agent.account = 0
      agent.agent_status = AGENT_PASS_STATUS
      agent.save!
    end

    flash[:notice] = "提现操作成功"
    redirect_to('/users/agent_list')
  end
end
